package com.filter;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class EncodeWrapper extends HttpServletRequestWrapper {

	public EncodeWrapper(HttpServletRequest request) {
		super(request);

	}

	@Override
	public String getParameter(String name) {
		String value = super.getParameter(name);
		value = null != value ? value : "";
		try {
			value = new String(value.getBytes("iso-8859-1"), "gbk");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return value;
	}

	@Override
	public String[] getParameterValues(String name) {
		String[] values = super.getParameterValues(name);
		try {
			for (int i = 0; i < values.length; i++) {
				values[i] = new String(values[i].getBytes("iso-8859-1"), "gbk");
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return values;
	}

}
